package com.fany.utils;

import android.graphics.PointF;

public class AlgorithmUtils
{
	public static double calculateDistance(PointF begin, PointF end)
	{
		double x = begin.x - end.x;
		double y = begin.y - end.y;
		return Math.sqrt(x * x + y * y);
	}

	public static PointF calculateCirclePoint(PointF center, double radius, double angle)
	{
		PointF point = new PointF();
		point.x = center.x + (float) (radius * Math.cos(angle * Math.PI / 180));
		point.y = center.y + (float) (radius * Math.sin(angle * Math.PI / 180));
		return point;
	}

	public static int computeAngle(PointF center, double x, double y)
	{
		double distance = (double) Math.sqrt(((x - center.x) * (x - center.x) + (y - center.y) * (y - center.y)));
		int degree = (int) (Math.acos((x - center.x) / distance) * 180 / Math.PI);
		if (y < center.y)
		{
			degree = -degree;
		}
		if (degree < 0)
		{
			degree = 360 + degree;
		}
		return degree;
	}

	public static double calculateTriangleAngle(double a, double b)
	{
        return Math.atan(a/b)/Math.PI*180;
	}
}
